package cn.sc.allinpay.allfavour.business.common.adapter;

import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import cn.pai.common.adapter.BaseRecyAdapter;
import cn.pai.common.utils.AmtUtils;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.business.common.data.DistCouponData;

/**
 * description：发券适配器
 * author：pany
 * on 2018/7/17 15:02
 */
public class DistCouponAdapter extends BaseRecyAdapter<DistCouponAdapter.MyViewHoder, DistCouponData> {

    @Override
    public int layoutId() {
        return R.layout.item_dist_coupon;
    }

    @Override
    public MyViewHoder onCreateViewHolder(View view) {
        return new MyViewHoder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHoder holder, int position, final DistCouponData data) {
        holder.tvName.setText(data.getName());
        if (0==data.getAmtType()) {//元
            holder.itemView.setBackgroundColor(Color.parseColor("#00b0f0"));
            holder.tvType.setText("类型：金额券");
            holder.tvNum.setText("库存：" + data.getTotCoup());
        } else {
            if (1==data.getAmtType()) {//抵扣
                holder.itemView.setBackgroundColor(Color.parseColor("#f28226"));
                holder.tvType.setText("类型：抵扣券");
            } else {
                holder.itemView.setBackgroundColor(Color.parseColor("#7fb645"));//92d050
                holder.tvType.setText("类型：计次券");
            }
            holder.tvNum.setText("库存：" + data.getTotCoup() + data.getUnit());
        }
        if (0==data.getAmtType()) {
            holder.tvAmt.setText("面额：" + AmtUtils.changeF2Y(data.getAmt())+data.getUnit());
        } else {
            holder.tvAmt.setText(null);
        }
    }


    class MyViewHoder extends RecyclerView.ViewHolder {

        AppCompatTextView tvName;//卡券名称
        AppCompatTextView tvType;//类型
        AppCompatTextView tvNum;//库存
        AppCompatTextView tvAmt;//售价

        public MyViewHoder(View itemView) {
            super(itemView);
            // TODO Auto-generated constructor stub
            tvName = itemView.findViewById(R.id.tvName);
            tvType = itemView.findViewById(R.id.tvType);
            tvNum = itemView.findViewById(R.id.tvNum);
            tvAmt = itemView.findViewById(R.id.tvAmt);
        }
    }
}
